home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8341 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.3 KB

  1. Path: ees1a0.engr.ccny.cuny.edu!rpi!not-for-mail
  2. From: rlister@pyramid.com (Robert Lister)
  3. Newsgroups: gnu.g++.help,comp.lang.c++.moderated,comp.lang.c++
  4. Subject: Re: Multiple copies of Virtual Table
  5. Date: 16 Feb 1996 23:36:24 -0000
  6. Organization: Pyramid Technology
  7. Sender: cppmods@netlab.cs.rpi.edu
  8. Approved: herbs@connobj.com
  9. Message-ID: <4g34do$5b6@netlab.cs.rpi.edu>
  10. References: <4fvj0l$ii7@netlab.cs.rpi.edu> <4g1pqs$pvl@netlab.cs.rpi.edu>
  11. NNTP-Posting-Host: netlab.cs.rpi.edu
  12. X-Original-Date: 16 Feb 1996 15:09:28 -0800
  13.  
  14.  
  15. In article <4g1pqs$pvl@netlab.cs.rpi.edu>, overhaul@nmia.com (Daniel N.
  16. Sands) writes:
  17. |> Mike ODowd wrote:
  18. |> #-> I have noticed that the size of my code has been growing
  19. |> #-> at an alarming rate recently. After some investigation, I
  20. |> #-> discovered that it is due to multiple copies of virtual tables.
  21. |> #-> 
  22. |> #-> It seems that each object file that accesses a class, ends up
  23. |> #-> with a copy of that class' virtual table. I one case, I counted 
  24. |> #-> 91 object files that contain a copy of the same virtual table.
  25. |> #-> 
  26. |> #-> The virtual tables are taking up something like 25% of my code.
  27. |> #-> 
  28. |> #-> Please tell me that there is a way around this, that my code size
  29. |> #-> is not going to expand exponentially.
  30. |> #-> 
  31. |> #-> I am using gcc v2.6.0.
  32. |> 
  33. |> I may know what's up:  If you define instances of your class in the 
  34. |> header file:
  35. |> 
  36. |> <foo.h>
  37. |> 
  38. |> Myclass Foo1;
  39. |> 
  40. |> Every file that includes foo.h will make a copy of Foo1, and a virtual 
  41. |> table to match.  Make sure all data declared in the header files is 
  42. |> "extern".  Then define the actual instance in one of your modules.
  43. |> 
  44. |> { This isn't a clear example - anyone care to summise the problems of
  45. |>   inlines/templates and vtbl emmision ?? -mod}
  46. |> 
  47. |>       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  48. |>       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  49. |>       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  50. |>       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  51.  
  52. I observed the same thing with Sparcworks (3.0.1 or 4.0.1?)
  53. Many compilers have the following option which will save you space.
  54.  
  55.      +e[01]    Only to be used on classes for which virtual functions are
  56.                present, and all the virtual functions are either defined as
  57.                inline or pure.  In this circumstance, this option optimizes
  58.                a program to use less space by ensuring that only one
  59.                virtual table per class is generated.  +e1 causes virtual
  60.                tables to be external and defined.  +e0 causes virtual
  61.                tables to be external but only declared.  This option is
  62.                ignored for any class that contains an out-of-line virtual
  63.                function.
  64.  
  65. Although the above description (from our Pyramid compiler) claims
  66. that this only applies to classes with no non-inline functions
  67. (and thus no implementation object file), I believe it applies
  68. to all classes with Sparcworks.  It is a useful feature if you need
  69. to put objects with virtual functions in shared memory.
  70.  
  71. - Bob
  72. -- 
  73. Robert Lister
  74.  
  75.       [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
  76.       [  Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm  ]
  77.       [  Moderation policy: http://www.connobj.com/cpp/guide.htm  ]
  78.       [      Comments? mailto:c++-request@netlab.cs.rpi.edu       ]
  79.